package com.example.myapplication;

import android.content.Intent;

import android.os.Bundle;

import android.text.TextUtils;
import android.util.Log;
import android.view.View;


import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.example.myapplication.databinding.ActivityMainBinding;

public class MainActivity extends AppCompatActivity {

    private ActivityMainBinding binding;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        binding = ActivityMainBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });

//        editText1 = findViewById(R.id.edit1);
//        editText2 = findViewById(R.id.edit2);
//        打印日志

        Log.d("Te", "测试一下2.0");
        binding.btn.setText(R.string.test);
        binding.edit1.setText(String.valueOf(123));
    }

//    跳转其他的页面
    public void click1(View view) {
        if(TextUtils.isEmpty(binding.edit1.getText()) || TextUtils.isEmpty(binding.edit2.getText())){
            Toast.makeText(this, "计算输入框不能为空", Toast.LENGTH_SHORT).show();
            return;
        }
//        生成一个Intent对象
        String edit1 = binding.edit1.getText().toString();
        String edit2 = binding.edit2.getText().toString();
        Intent intent = new Intent();
//        传递的值
        intent.putExtra("edit1", edit1);
        intent.putExtra("edit2", edit2);
        intent.setClass(MainActivity.this, otherActivity.class);
        MainActivity.this.startActivity(intent);
    }

    @Override
    protected void onStart() {
        super.onStart();
        Log.d("TAG", "A onStart: ");
    }

    @Override
    protected void onResume() {
        super.onResume();
        Log.d("TAG", "A onResume ");
    }

    @Override
    protected void onStop() {
        super.onStop();
        Log.d("TAG", "A stop ");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Log.d("TAG", "A Destory ");
    }

    public void clickLay(View view) {
        Intent intent = new Intent();
        intent.setClass(MainActivity.this, demo.class);
        startActivity(intent);
    }
}